package com.session02;

public class Test1 {
    public static void main(String[] args) {
        //   2/1, 3/2, 5/3, 8/5, 12/8.......求出该分数 序列前20项之和
/*        double sum = 0;
        int flag = 0;
        double i = 1, j = 2, k = 1;
        while (flag < 20) {
            sum += j / i;
            i = j;
            j += k;
            k++;
            flag++;
        }*/

        //  2/1, 3/2, 5/3, 8/5, 13/8, 21/13
        double a = 1, b = 2, sum = 0, temp;
        for (int i = 1; i <= 20; i++) {
            sum = sum + b / a;
            temp = b;
            b = a + b;
            a = temp;
        }
        System.out.println(sum);
    }
}
